package com.freesky.biz.icbc.controller;

import com.freesky.biz.icbc.domain.TIcbcXiangRecord;
import com.freesky.biz.icbc.domain.TIcbcXiangRecordImport;
import com.freesky.biz.icbc.domain.TPartnership;
import com.freesky.biz.icbc.service.IIcbcXiangRecordService;
import com.freesky.biz.icbc.service.IPartnershipService;
import com.freesky.common.annotation.Log;
import com.freesky.common.annotation.RepeatSubmit;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import com.freesky.common.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工行相荐礼
 */
@RestController
@RequestMapping("/icbc/xiangrecord")
public class IcbcXiangRecordController extends BaseController {

    @Autowired
    private IIcbcXiangRecordService xiangRecordService;

    /**
     * 工行相荐礼列表
     */
    @PreAuthorize("@ss.hasPermi('icbc:xiangrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(TIcbcXiangRecord entity) {
        startPage();
        List<TIcbcXiangRecord> list = xiangRecordService.findList(entity);
        return getDataTable(list);
    }

    @Log(title = "工行相荐礼", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('icbc:xiangrecord:export')")
    @GetMapping("/export")
    public AjaxResult export(TIcbcXiangRecord entity,
                             HttpServletResponse response) {
        return xiangRecordService.exportFile(entity);
    }

    @PreAuthorize("@ss.hasPermi('icbc:xiangrecord:list')")
    @GetMapping("/listImport")
    public TableDataInfo listImport(TIcbcXiangRecordImport entity) {
        startPage();
        List<TIcbcXiangRecordImport> list = xiangRecordService.findImportList(entity);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('icbc:xiangrecord:import')")
    @RepeatSubmit
    @RequestMapping("/template")
    public void exportExcel() {
        xiangRecordService.exportExcel();
    }

    //导入工行相荐礼
    @PreAuthorize("@ss.hasPermi('icbc:xiangrecord:import')")
    @Log(title = "工行相荐礼", businessType = BusinessType.IMPORT)
    @RepeatSubmit
    @RequestMapping("/import")
    public AjaxResult importExcel(MultipartFile file) throws Exception {
        if (file.isEmpty()) {
            throw new CustomException("导入文件不能为空！");
        }
        return xiangRecordService.importExcel(file);
    }

}
